//
//  ClassWithTructVC.swift
//  swiftDemo
//
//  Created by yaqiang bi on 2017/3/16.
//  Copyright © 2017年 毕小强. All rights reserved.
//
//  类和结构体

import UIKit

class ClassWithTructVC: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
        /*
         *      结构体可以自动生成成员初始化器
         *      类不可以
         **/
        let someResolution = Resolution()
        let someVideoMode = VideoMode()
        print(someResolution.width)
        print(someVideoMode.resolution.height)
        someVideoMode.resolution.width = 1280
        
        /*
         *      结构体和枚举都是值类型
         *      值类型是一种当它被指定到常量或者变量,或者被传递给函数时会被拷贝的类型
         *      所有的基本数据类型都是值类型
         **/
        var hd = Resolution(width: 400, height: 400)
        var cinema = hd
        hd.width = 100
        cinema.width = 200
        print(hd.width)
        print(cinema.width)
        
        
        /*
         *      类是引用类型
         *      引用类型被赋值到一个常量,变量或者本身被传递到一个函数的时候不会被拷贝
         **/
        let tenEighty = VideoMode()
        tenEighty.resolution = hd
        tenEighty.interlaced = true
        tenEighty.name = "1080i"
        tenEighty.frameRate = 25.0
        
        let alsoTenEighty = tenEighty
        alsoTenEighty.frameRate = 30.0
        print(tenEighty.frameRate)
        
        if tenEighty === alsoTenEighty {
            print("tenEighty and alsoTenEighty is the same VideoMode")
        }
        
        // Do any additional setup after loading the view.
    }
    //生命一个类和结构体
    struct Resolution {
        var width = 0
        var height = 0
    }
    class VideoMode {
        var resolution = Resolution(width: 1290, height: 2000)
        var interlaced = false
        var frameRate = 0.0
        var name:String?
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
